import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/a_elder/models/elder_entity.dart';
import 'package:ls_work/viewmodel/medical/medical_record_view_model.dart';

class MedicalRecordPage extends BaseStatefulMvvmWidget{
  final ElderInfo? info;

  MedicalRecordPage({this.info});

  @override
  State<StatefulWidget> createState() => _MedicalRecordState();

}

class _MedicalRecordState extends BaseMvvmListState<MedicalRecordViewModel,MedicalRecordPage>{
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(title: Text("就医登记"),),
      body: Stack(
        children: [
          loadingContentWidget.setLocation(
              left: 0, right: 0, top: 0, bottom: 66),
          ElevatedButton(
            onPressed: () {
              viewModel.toAddSign();
            },
            child: CommonText("新增", textColor: Colors.white, textSize: 17),
            style: ButtonStyle(
                backgroundColor: WidgetStateProperty.all(Color(0xfff6ab00)),
                minimumSize: WidgetStateProperty.all(Size.fromHeight(45)),
            shape: WidgetStateProperty.all(StadiumBorder())),
          ).setLocation(left: 16, right: 16, bottom: 16)
        ],
      ),
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    var date = DateTime.parse(item.leaveTime??"");
    var dateFormat = [yyyy,"年",mm,"月",dd,"日"," ",D];
    var timeFormat = [HH,":",nn];
    return Column(
      children: [
        CommonText("${formatDate(date, dateFormat, LocaleType.zh)}",
            textSize: 12, textColor: Color(0xff666666))
            .addToContainer(margin: EdgeInsets.symmetric(vertical: 15)),
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            CommonText("${formatDate(date, timeFormat, LocaleType.zh)}", textColor: Color(0xff999999))
                .addToContainer(margin: EdgeInsets.only(top: 3)),
            Container(
              width: 18,
            ),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    CommonText("${item.customer}", fontWeight: FontWeight.bold),
                    Container(
                      width: 12,
                    ),
                    // CommonText("2#1-02", textSize: 14)
                  ],
                ),
                Container(
                  height: 8,
                ),
                CommonText("记录人：${item.creator}", textSize: 14),
                Container(
                  height: 8,
                ),
                CommonText("病因类型：${item.medicalCause}", textSize: 14),
                Container(
                  height: 8,
                ),
                CommonText("就医原因：${item.medicalReasons}", textSize: 14),

                Container(
                  height: 8,
                ),
                Row(
                  children: [
                    CommonText("就医形式：${item.medicalTreatment}", textSize: 14).setWeight(1),
                    CommonText("就医计划：${item.medicalPlanName}", textSize: 14).setWeight(1),
                  ],
                ),
                Container(
                  height: 8,
                ),
                CommonText("离开机构时间：${item.leaveTime}", textSize: 14),
                Container(
                  height: 8,
                ),
                CommonText("返回机构时间：${item.backTime}", textSize: 14),

                Container(
                  height: 15,
                ),
              ],
            ).setWeight(1)
          ],
        ).addToContainer(margin: EdgeInsets.symmetric(horizontal: 16))
      ],
    ).addToContainer(color: Colors.white);
  }

  @override
  MedicalRecordViewModel createViewModel() {
    return MedicalRecordViewModel(context);
  }

}